package com.itao.mybatis;

import com.itao.mybatis.entity.User;
import com.itao.mybatis.mapper.UserMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.util.List;

/**
 * @author sjt
 * @Date 2024/12/19 10:48
 */
public class Main {

    public static void main(String[] args) throws IOException {
        ClassPathResource resource = new ClassPathResource("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resource.getInputStream());
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        //int insert = mapper.insertUser(new User("sjt", 18));
        List<User> users = mapper.selectUser(new User("sjt", 18));
        System.out.println(users);
        sqlSession.commit();
    }
}
